import urllib.request


def auth_nei_wang():
    # 1.用户名和密码
    user = "admin"
    pwd = "admin123"
    nei_url = "http://192.168.179.66"

    # 2.密码管理器

    pwd_manager = urllib.request.HTTPPasswordMgrWithDefaultRealm()

    pwd_manager.add_password(None, nei_url, user, pwd)

    # 3. 认证的处理器
    auth_handle = urllib.request.HTTPBasicAuthHandler(pwd_manager)

    # 4. opener
    opener = urllib.request.build_opener(auth_handle)

    # 5.open
    response = opener.open(nei_url)

auth_nei_wang()

